package com.smart.controller;

import com.github.pagehelper.PageInfo;
import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.HotWorkRequest;
import com.smart.model.vo.ListQuerySuperviseCount;
import com.smart.service.HotWorkService;
import com.smart.model.vo.HotWorkVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/hotWork")
@Api(value = "动火作业模块", tags = {"动火作业模块"})
public class HotWorkController {

    @Autowired
    private HotWorkService hotWorkService;

    @WebAccess(login = true)
    @ApiOperation(value = "查询动火作业详情", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getDetail/{id}")
    public WebResponse<HotWorkVO> getDetailByKey(@PathVariable("id") long id) {
        return WebResponse.build(hotWorkService.getDetailByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation("动火作业清单查询(云监管、云管理端、云服务复用)")
    @PostMapping("/pageDetailedList")
    public WebResponse<PageInfo<HotWorkVO>> pageDetailedList(@RequestBody HotWorkRequest request, @SortDefault(sort = "h.create_time",direction = Sort.Direction.DESC) Pageable pageable) {
        return WebResponse.build(hotWorkService.pageDetailedList(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管-动火作业管理列表分页查询")
    @PostMapping("/listQuerySupervise")
    public WebResponse<List<HotWorkVO>> listQuerySupervise(@RequestBody HotWorkRequest request) {
        return WebResponse.build(hotWorkService.listQuerySupervise(request));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管-动火作业管理列表统计")
    @PostMapping("/listQuerySuperviseCount")
    public WebResponse<ListQuerySuperviseCount> listQuerySuperviseCount(@RequestBody HotWorkRequest request) {
        return WebResponse.build(hotWorkService.listQuerySuperviseCount(request));
    }

    @WebAccess(login = true)
    @ApiOperation("云管理-动火作业管理列表分页查询")
    @PostMapping("/listQueryManage")
    public WebResponse<List<HotWorkVO>> listQueryManage(@RequestBody HotWorkRequest request,@SortDefault(sort = "p.create_time",direction = Sort.Direction.DESC) Pageable pageable) {
        return WebResponse.build(hotWorkService.listQueryManage(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("云服务端-动火作业新增")
    @PostMapping("/add")
    public WebResponse<Map<String, Object>> add(@Valid @RequestBody HotWorkRequest request) {
        return WebResponse.build(hotWorkService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("云服务端-动火作业修改")
    @PostMapping("/update")
    public WebResponse<Boolean> updateByKey(@Valid @RequestBody HotWorkRequest request) {
        return WebResponse.build(hotWorkService.updateByKey(request));
    }



//    @WebAccess(login = true)
//    @ApiOperation("删除")
//    @PostMapping("/delete/{id}")
//    public WebResponse<Boolean> deleteByKey(@PathVariable("id") long id) {
//        return WebResponse.build(hotWorkService.deleteByKey(id));
//    }

    @WebAccess(login = true)
    @ApiOperation("动火人、看火人输入后校验")
    @PostMapping("/verify")
    public WebResponse<Boolean> verify(@RequestParam("userName") String  userName) {
        return WebResponse.build(hotWorkService.verify(userName));
    }
}
